package com.ycj.entropy.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String format(Date date) {
        return formatter.format(date);
    }

    public static String format(long millis) {
        return DateUtil.format(new Date(millis));
    }

    public static String now() {
        return format(new Date());
    }

    public static long toMills(String date) {
        try {
            return formatter.parse(date).toInstant().toEpochMilli();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0L;
        }
    }
}
